package cn.edu.xmu.oomall.liquidation.model.bo.liquid.expenditure;

import cn.edu.xmu.oomall.liquidation.microservice.PaymentService;
import cn.edu.xmu.oomall.liquidation.microservice.vo.RefundRetVo;
import cn.edu.xmu.oomall.liquidation.model.bo.liquid.calc.CalcTotal;
import cn.edu.xmu.oomall.liquidation.model.bo.liquid.util.LiquidUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.List;

public abstract class BaseRefundLiquid {
    @Autowired
    protected LiquidUtil liquidUtil;

    protected abstract CalcTotal liquidateSingleRefund(RefundRetVo refund, LocalDateTime liquidDateTime);

    public CalcTotal liquidate(List<RefundRetVo> refundList, LocalDateTime liquidDateTime) {
        CalcTotal platformCalcTotal = new CalcTotal(liquidUtil.getPlatformCalcFieldList());
        for(RefundRetVo refund : refundList) {
            CalcTotal calcTotal = liquidateSingleRefund(refund, liquidDateTime);
            // 更新平台统计记录
            platformCalcTotal.add(calcTotal);
            // 修改支付单状态为已清算
            liquidUtil.changeRefundLiquidated(refund.getId());
        }
        return platformCalcTotal;
    }
}
